package com.ruoyi.garbage.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.excel.ExcelUtils;
import com.ruoyi.garbage.domain.ImageClassify;
import com.ruoyi.garbage.service.IImageClassifyService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 图像识别记录Controller
 *
 * @author 刘哲贤
 * @date 2023-01-07
 */
@RestController
@RequestMapping("/admin/imageClassify")
public class ImageClassifyController extends BaseController {
    @Resource
    private IImageClassifyService imageClassifyService;

    /**
     * 查询图像识别记录列表
     */
    @PreAuthorize("@ss.hasPermi('admin:imageClassify:list')")
    @GetMapping("/list")
    public TableDataInfo list(ImageClassify imageClassify) {
        startPage();
        List<ImageClassify> list = imageClassifyService.selectImageClassifyList(imageClassify);
        return getDataTable(list);
    }

    /**
     * 导出图像识别记录列表
     */
    @PreAuthorize("@ss.hasPermi('admin:imageClassify:export')")
    @Log(title = "图像识别记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ImageClassify imageClassify) {
        List<ImageClassify> list = imageClassifyService.selectImageClassifyList(imageClassify);
        ExcelUtils<ImageClassify> util = new ExcelUtils<ImageClassify>(ImageClassify.class);
        util.exportData(response, list, "图像识别记录数据");
    }

    /**
     * 获取图像识别记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('admin:imageClassify:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(imageClassifyService.selectImageClassifyById(id));
    }

    /**
     * 新增图像识别记录
     */
    @PreAuthorize("@ss.hasPermi('admin:imageClassify:add')")
    @Log(title = "图像识别记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ImageClassify imageClassify) {
        return toAjax(imageClassifyService.insertImageClassify(imageClassify));
    }

    /**
     * 修改图像识别记录
     */
    @PreAuthorize("@ss.hasPermi('admin:imageClassify:edit')")
    @Log(title = "图像识别记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ImageClassify imageClassify) {
        return toAjax(imageClassifyService.updateImageClassify(imageClassify));
    }

    /**
     * 删除图像识别记录
     */
    @PreAuthorize("@ss.hasPermi('admin:imageClassify:remove')")
    @Log(title = "图像识别记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(imageClassifyService.deleteImageClassifyByIds(ids));
    }
}
